window.onload = function () {
    $username = $('.header .header-c .header-right .username')
    axios.get("http://localhost:8080/getUserInfo")
        .then(function (response) {
            console.log(response)
            let username = response.data.data
            $username.text(username);
        })
        .catch(function (error) {
            console.log(error)
        })

    $shoppingCartArea = $('.shopping_cart_content .main table')
    $orderNum = $(".shopping_cart_content .header-s .cart p span i")
    axios.get("http://localhost:8080/getShoppingCart")
        .then(function (response) {
            console.log(response);
            // let orders = JSON.stringify(response.data)
            // $shoppingCartArea.text(orders)\
            let orders = response.data
            console.log(orders);
            $orderNum.text(orders.length)
            orders.forEach(function (order) {
                let status = order.order_status
                if (status == 0) {
                    status = '未支付'
                } else if (status == 1) {
                    status = '已支付未发货'
                } else {
                    status = '已发货'
                }
                let content = '<tr><td>' + order.order_id + '</td><td>' + order.iSBN + '</td><td>' + new Date(order.order_time).toLocaleString() + '</td><td>' + order.quantity + '</td><td>' + order.total_amount + '</td><td>' + status + '</td></tr>'
                $shoppingCartArea.append(content)
            });

        })
        .catch(function (error) {
            console.log(error)
        })

}